<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/20
 * Time: 13:37
 */
namespace Common\Model;

class ChannelModel extends BaseModel {

    const STATUS_DELETE = -1;
    /**
     * 获取单个栏目
     * @param $title
     * @return mixed
     */
    public function getChannelByTitle($title){
        $condition = array(
            'title' => $title
        );
        $res = $this->where($condition)->limit(1)->find();
        return $res;
    }

    public function getChannel($title,$ename,$mould) {

        $table = '__CHANNEL__ cha';
        $jionTable = '__MOULD__ mo on cha.mould = mo.tablename';
        $field = 'cha.* , mo.name mould_name';
        $opt = array();
        if($title) {
            $opt['cha.title'] = array('like','%'.$title.'%');
        }
        if($ename) {
            $opt['cha.ename'] = array('like','%'.$ename.'%');
        }
        if($mould) {
            $opt['mo.tablename'] = array('like','%'.$mould.'%');
        }

        $res = $this->table($table)->join($jionTable)->field($field)->where($opt)->select();
        return $res;
    }
}